/*=================================页面事件============================================================*/
function hydtLoad(){
	createLeftTopMenuForKYXX();//行业动态页面，生成左上角的目录
	queryAllSettings();
	queryHYDTTitleForDisplay(1);
}

function loadNews(pageNo){
	queryHYDTTitleForDisplay(pageNo);
}

function loadOneNews(newsID){
	var obj = window;
    obj.newsID = newsID;
	window.open("hydtContent.jsp?id="+ Math.random());
}

//输入页码，跳转到指定页面的操作
function changeRandomPage(){
	var pageCount = document.getElementById("pageCount").value;
	var inputValue = document.getElementById("pageNoInput").value;
	if(!isPositiveInteger(inputValue)){
		alert("请输入一个正整数。");
		pageNoInput.focus();
		pageNoInput.select();
		return;
	}
	if(parseInt(inputValue) > parseInt(pageCount)){
		alert("您输入的页码超过最大页码，请重新输入。");
		pageNoInput.focus();
		pageNoInput.select();
		return
	}
	loadNews(inputValue);
}

/*=================================信息获取============================================================*/

//获取指定数量行业动态的标题和时间,页面展示部分，需要生成分页工具栏
function queryHYDTTitleForDisplay(pageNo){
	if(bXmlHttpSupport) {
    	var sUrl = "queryHYDTTitleForDisplay.action";
    	var params ="pageNo="+pageNo;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	var HYDTTitleList = oRequest.newsList;
            	pageBar.innerHTML = oRequest.pageBar;
            	putNewsIntoTable(HYDTTitleList);
            	makeTableColor("tableHYDTList","#FFCC66","white");
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

/*=================================信息展示============================================================*/

//客运信息页面，生成左上角的目录
function createLeftTopMenuForKYXX(){
	if(bXmlHttpSupport) {
    	var sUrl = "findSettings.action";
    	var params ="item=LeftTopMenu&setKey=xwjj";
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	var string = oRequest.settings.setValue;
            	news.innerHTML = string;
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

/*=================================数据处理============================================================*/
//将读取的新闻列表放入table中
function putNewsIntoTable(HYDTTitleList){
	var rowlength = tableBodyHYDTList.rows.length; 
	for(var i=0;i <rowlength;i++) { 
		tableBodyHYDTList.deleteRow(0); 
	}
	for (var i in HYDTTitleList){
		var rowObj = document.createElement("tr");
		addOneTD(rowObj, "▶&nbsp" + "<a href='javascript:loadOneNews("+HYDTTitleList[i][0]+");'>" + HYDTTitleList[i][1] + "</a>", "tdFirst");
		addOneTD(rowObj, HYDTTitleList[i][2].replace("T", " "), "tdLast");
		tableBodyHYDTList.appendChild(rowObj);
	}
}

/*=================================其他============================================================*/

//给页面的table的行改变颜色
function makeTableColor(obTable, hoverColor, outColor) {
	var t = document.getElementById(obTable).getElementsByTagName("tr");
	for ( var i = 0; i < t.length; i++) {
		t[i].onmouseover = function() {
				this.style.backgroundColor = hoverColor;
		};
		t[i].onmouseout = function() {
				this.style.backgroundColor = outColor;
		};
	}
}